var request = require('request'),
    username = "admin",
    password = "Mdc12345++",
    url = "http://robinv.free.idcfengye.com",
    auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
function http(params = {}){
  return new Promise(resolve =>{
    request(
      {
          url : url,
          headers : {
            "Authorization" : auth,
            'content-type': 'Text'
          },
          body: JSON.stringify(params),
          method: 'post'
      },
      function (error, response, body) {
        if(response.statusCode === 200) {
          const result = JSON.parse(body)
          resolve(result)
        } else {
          resolve(false)
        }
          // Do more stuff with 'body' here
      }
    );
  })
}
module.exports = function (app) {
  app.use('/api/usdt/newWallet', {
    find: async () => {
      const {result: address} = await http({"method":"getnewaddress","params":[]})
      const {result: privateKey} = await http({"method":"dumpprivkey","params":[address]})
      return Promise.resolve({
        address,
        privateKey
      })
    }
	})
	app.use('/api/usdt/getBalance', {
    find: async ({query:{address}}) => {
      const {result: {balance}} = await http({"method":"omni_getbalance","params":[address, 31]})
      return Promise.resolve({
        balance
      })
    }
  })
} 